package me.zhao.proxy.jdkproxy;

import java.lang.reflect.Proxy;

import me.zhao.proxy.Car;
import me.zhao.proxy.Moveable;

/**
 * jdk动态代理测试类
 * @author zhaoying
 *
 */
public class TestJdkProxy {

	public static void main(String[] args) {
		Car car = new Car();
		TimeHandler th = new TimeHandler(car);
		Class<?> cls = car.getClass();
		
		
		
		/**
		 * loader 被代理类加载器
		 * interfaces 实现接口
		 * InvocationHandler 
		 * 返回动态代理对象
		 */
		Moveable timecar = (Moveable) Proxy.newProxyInstance(cls.getClassLoader(), cls.getInterfaces(), th);
		
		LogHandler lh = new LogHandler(timecar);
		Moveable logCar = (Moveable) Proxy.newProxyInstance(cls.getClassLoader(), cls.getInterfaces(), lh);
		logCar.move();
	}

}
